import java.io.IOException;
import javax.media.j3d.*;
import javax.vecmath.*;


public class communicationBridge {
    private tcpipLayer connectToSocket = new tcpipLayer();
    void sendWorldInfo(Client connectionToPlayer, TransformGroup puck, TransformGroup myHandle, Vector3f puckdirection) throws IOException {
        Vector3d cordsPuck = new Vector3d();
        Vector3d cordsMyHandle = new Vector3d();
        //create a 3D transform
        Transform3D changesToSend = new Transform3D();
        Transform3D changesToSend2 = new Transform3D();
        //fetch the transform data from the puck object
        puck.getTransform(changesToSend);
        myHandle.getTransform(changesToSend2);
        changesToSend.get(cordsPuck);
        changesToSend2.get(cordsMyHandle);
        String dataToSend = "<data><puck><x>" + cordsPuck.x + "</x><y>" + cordsPuck.y + "</y><z>" + cordsPuck.z + "</z>"+"<velocity><x>"+puckdirection.x+"</x><y>"+puckdirection.y+"</y><z>"+puckdirection.z+"</z></velocity>"+"</puck><handle><x>" + cordsMyHandle.x + "</x><y>" + cordsMyHandle.y + "</y><z>" + cordsMyHandle.z + "</z></handle></data>";
        //System.out.println(dataToSend);
        //send the transform data, in VECTOR form, to the TCP/IP layer to send
        connectToSocket.sendData(connectionToPlayer,dataToSend);
    }

    void updateCordForObject(Server tcpServer, TransformGroup othersHandle, String objectName) {
    	//backup cords
    	Transform3D backupCords = new Transform3D();
    	Vector3d backupHold = new Vector3d();
    	othersHandle.getTransform(backupCords);
    	backupCords.get(backupHold);
    	
    	
    	
        //create a 3D transform which will be applied to object
        Transform3D changes = new Transform3D();
        //create vector to hold updated cordinates for object
        Vector3d hold = new Vector3d();
        //goto TCP/IP layer to fetch data
        connectToSocket.getData(tcpServer,hold,backupHold, objectName);
        //set the changes in the transform group
        //if(hold.x!=0 && hold.y!=0 && hold.z!=0) {
        
       // if(hold==backupHold){
        //	System.out.println("missed data");
        //}
        changes.set(hold);
            //update the objects transform group
        othersHandle.setTransform(changes);
        //}
    }
    
    void updateVelocityForObject(Server tcpServer, Vector3f puckVel, String objectName) {
    	Vector3f backup = new Vector3f();
    	backup.x=puckVel.x;
    	backup.y=puckVel.y;
    	backup.z=puckVel.z;
    	connectToSocket.getVelocityData(tcpServer,puckVel,backup,objectName);
    }
    
    
    
}

